//
//  MainTabBarController.swift
//  Weibo007
//
//  Created by 闫崇 on 15/12/13.
//  Copyright © 2015年 闫崇. All rights reserved.
//

import UIKit 

class MainTabBarController: UITabBarController {
    
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        let tb = MainTabBar()
//        print(tabBar.items)
        //如果要替换 tabBar 可以再 viewDidLoad 中动手脚
        //使用 KVC 来动态的自定义 tabBar 
//        tabBar = MainTabBar()
        setValue(tb, forKey: "tabBar")
        
        tb.compoesButton.addTarget(self, action: "composedButtonClicked", forControlEvents: UIControlEvents.TouchUpInside)
        
        
        
        /**
        添加所有控制器
        */
        addChildViewControllers()
        
    }
    
    
    func composedButtonClicked() {
//        print(__FUNCTION__)
    }
    
    
    
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
        
//        print(tabBar.items)
    }
    
    
    
    /**
     添加所有控制器
     */
    private func addChildViewControllers(){
        
        
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
        
    }
    
    
    /**
     添加控制器
     */
    private func addChildViewController(vc:UIViewController,title:String,imageName:String){
        
        //设置主题颜色 tintColor
        tabBar.tintColor = UIColor.orangeColor()
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")
        
        let nav = UINavigationController(rootViewController: vc)
        
        addChildViewController(nav)
        
    }
    
    

}
